package com.quan.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quan.common.bean.PageBean;
import com.quan.common.core.MyBaseServiceImpl;
import com.quan.system.entity.SystemFile;
import com.quan.system.mapper.SystemFileMapper;
import com.quan.system.service.SystemFileService;

/**
 * <p>
 * 图片表 服务实现类
 * </p>
 *
 * @author 杨浩泉
 * @since 2020-01-02
 */
@Service
public class SystemFileServiceImpl extends MyBaseServiceImpl<SystemFileMapper, SystemFile> implements SystemFileService {

	@Autowired
	private SystemFileMapper mapper;
	
	@Override
	public IPage<SystemFile> selectMyPage(SystemFile entity, PageBean pageBean) {
		Page<SystemFile> page = new Page<>(pageBean.getPage(), pageBean.getLimit());
		
		// 排序
		if(StringUtils.isNotBlank(pageBean.getSortOrder()) && StringUtils.isNotBlank(pageBean.getSortName())) {
			List<OrderItem> orders = new ArrayList<OrderItem>();
			
			OrderItem orderItem = new OrderItem();
			orderItem.setColumn(pageBean.getSortName());
			orderItem.setAsc(!pageBean.getSortOrder().equalsIgnoreCase("DESC"));
			
			orders.add(orderItem);
			page.setOrders(orders);
		}
		return this.mapper.selectMyPage(page, entity);
	}


}
